namespace EyeOpen.Aop.UI.Con
{
    using System;
    using System.Collections.Generic;
    using log4net.Appender;
    using log4net.Core;
    using log4net.Layout;
    using EyeOpen.Log4NetExtensions;
    using Log4NetExtensions.Appenders;

    [Serializable]
    public class SampleLog4NetFluentConfigurator : Log4NetFluentConfigurator
    {
        protected override IEnumerable<IAppender> CreateAppenderList()
        {
            IList<IAppender> appenderList = new List<IAppender>();

            var consoleAppender =
                new ConsoleAppender
                    {
                        Threshold = Level.Debug,
                        Layout = PatternLayout
                    };

            var exceptionFileAppender =
                new CustomFileAppender(LogDirectory)
                    {
                        AppendToFile = true,
                        Layout = ExceptionLayout,
                        CustomFile = ReadKeyFromConfigurationFile("ExceptionFile"),
                    };

            var traceFileAppender =
                new CustomFileAppender(LogDirectory)
                    {
                        Layout = XmlLayout,
                        AppendToFile = true,
                        CustomFile = ReadKeyFromConfigurationFile("TraceFile"),
                    };

            var usageFileAppender =
                new CustomFileAppender(LogDirectory)
                    {
                        Layout = XmlLayout,
                        AppendToFile = true,
                        CustomFile = ReadKeyFromConfigurationFile("SystemUsage"),
                        Threshold = Level.Info
                    };

            var exceptionEventLogAppender =
                new EventLogAppender
                    {
                        ApplicationName = "EyeOpen.Logging",
                        LogName = "EyeOpen.Logging",
                        Layout = new SimpleLayout(),
                        Threshold = Level.Error
                    };

            var usageAdoNetAppender = CreateAdoNetAppender("LoggingConnection", Level.Debug);

            appenderList.Add(consoleAppender);
            appenderList.Add(exceptionFileAppender);
            appenderList.Add(traceFileAppender);
            appenderList.Add(usageAdoNetAppender);
            appenderList.Add(usageFileAppender);
            appenderList.Add(exceptionEventLogAppender);

            return appenderList;
        }
    }
}